
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>012_时间日期处理 · 瑕家瑾轩_Note</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="xiajiajinxuan">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-page-toc-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-auto-scroll-table/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="013_死锁.html" />
    
    
    <link rel="prev" href="011_序列流水号.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../001_git教程/001_安装配置.html">
            
                <a href="../001_git教程/001_安装配置.html">
            
                    
                    001_git教程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../001_git教程/001_安装配置.html">
            
                <a href="../001_git教程/001_安装配置.html">
            
                    
                    001_安装配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../001_git教程/002_git常用语句及流程.html">
            
                <a href="../001_git教程/002_git常用语句及流程.html">
            
                    
                    002_git常用语句及流程
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../002_gitbook教程/001_安装配置及使用.html">
            
                <a href="../002_gitbook教程/001_安装配置及使用.html">
            
                    
                    002_gitbook教程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../002_gitbook教程/001_安装配置及使用.html">
            
                <a href="../002_gitbook教程/001_安装配置及使用.html">
            
                    
                    001_安装配置及使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../002_gitbook教程/002_生成文件目录.html">
            
                <a href="../002_gitbook教程/002_生成文件目录.html">
            
                    
                    002_生成文件目录
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../003_typora/001_typora-markdown语法.html">
            
                <a href="../003_typora/001_typora-markdown语法.html">
            
                    
                    003_typora
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../003_typora/001_typora-markdown语法.html">
            
                <a href="../003_typora/001_typora-markdown语法.html">
            
                    
                    001_typora-markdown语法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="001_ORACLE关键字执行顺序.html">
            
                <a href="001_ORACLE关键字执行顺序.html">
            
                    
                    004_Oracle
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="001_ORACLE关键字执行顺序.html">
            
                <a href="001_ORACLE关键字执行顺序.html">
            
                    
                    001_ORACLE关键字执行顺序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="002_关键字_between.html">
            
                <a href="002_关键字_between.html">
            
                    
                    002_关键字_between
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="003_数据库启停.html">
            
                <a href="003_数据库启停.html">
            
                    
                    003_数据库启停
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="004_http请求.html">
            
                <a href="004_http请求.html">
            
                    
                    004_http请求
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="005_NULL处理.html">
            
                <a href="005_NULL处理.html">
            
                    
                    005_NULL处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="006_交集_并集_差集.html">
            
                <a href="006_交集_并集_差集.html">
            
                    
                    006交集并集_差集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="007_字符处理.html">
            
                <a href="007_字符处理.html">
            
                    
                    007_字符处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="008_字符排序.html">
            
                <a href="008_字符排序.html">
            
                    
                    008_字符排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9" data-path="009_定时任务.html">
            
                <a href="009_定时任务.html">
            
                    
                    009_定时任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.10" data-path="010_数字处理.html">
            
                <a href="010_数字处理.html">
            
                    
                    010_数字处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.11" data-path="011_序列流水号.html">
            
                <a href="011_序列流水号.html">
            
                    
                    011_序列流水号
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.12" data-path="012_时间日期处理.html">
            
                <a href="012_时间日期处理.html">
            
                    
                    012_时间日期处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.13" data-path="013_死锁.html">
            
                <a href="013_死锁.html">
            
                    
                    013_死锁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.14" data-path="014_邮件发送.html">
            
                <a href="014_邮件发送.html">
            
                    
                    014_邮件发送
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.15" data-path="015_转义字符.html">
            
                <a href="015_转义字符.html">
            
                    
                    015_转义字符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.16" data-path="016_触发器.html">
            
                <a href="016_触发器.html">
            
                    
                    016_触发器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.17" data-path="017_同义词.html">
            
                <a href="017_同义词.html">
            
                    
                    017_同义词
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.18" data-path="018_json解析.html">
            
                <a href="018_json解析.html">
            
                    
                    018_json解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.19" data-path="019_文件读写.html">
            
                <a href="019_文件读写.html">
            
                    
                    019_文件读写
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.20" data-path="020_用户创建及授权.html">
            
                <a href="020_用户创建及授权.html">
            
                    
                    020_用户创建及授权
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.21" data-path="021_中文字符验证.html">
            
                <a href="021_中文字符验证.html">
            
                    
                    021_中文字符验证
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../005_EBS/001_ebs模块.html">
            
                <a href="../005_EBS/001_ebs模块.html">
            
                    
                    005_EBS
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../005_EBS/001_ebs模块.html">
            
                <a href="../005_EBS/001_ebs模块.html">
            
                    
                    001_ebs模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../005_EBS/002_API列表.html">
            
                <a href="../005_EBS/002_API列表.html">
            
                    
                    002_API列表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../005_EBS/003_FND_GLOBAL和FND_PROFILE.html">
            
                <a href="../005_EBS/003_FND_GLOBAL和FND_PROFILE.html">
            
                    
                    003_FND_GLOBAL和FND_PROFILE
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../005_EBS/004_IE相关设置.html">
            
                <a href="../005_EBS/004_IE相关设置.html">
            
                    
                    004_IE相关设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../005_EBS/005_MOAC.html">
            
                <a href="../005_EBS/005_MOAC.html">
            
                    
                    005_MOAC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../005_EBS/006_描述性弹性域.html">
            
                <a href="../005_EBS/006_描述性弹性域.html">
            
                    
                    006_描述性弹性域
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../005_EBS/007_编译.html">
            
                <a href="../005_EBS/007_编译.html">
            
                    
                    007_编译
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../005_EBS/008_界面数据查询.html">
            
                <a href="../005_EBS/008_界面数据查询.html">
            
                    
                    008_界面数据查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../005_EBS/009_获取当前lov查询语句.html">
            
                <a href="../005_EBS/009_获取当前lov查询语句.html">
            
                    
                    009_获取当前lov查询语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../005_EBS/010_表后缀.html">
            
                <a href="../005_EBS/010_表后缀.html">
            
                    
                    010_表后缀
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="../005_EBS/011_银行.html">
            
                <a href="../005_EBS/011_银行.html">
            
                    
                    011_银行
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.12" data-path="../005_EBS/012_错误代码及解释.html">
            
                <a href="../005_EBS/012_错误代码及解释.html">
            
                    
                    012_错误代码及解释
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.13" data-path="../005_EBS/013_WEBADI.html">
            
                <a href="../005_EBS/013_WEBADI.html">
            
                    
                    013_WEBADI
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.14" data-path="../005_EBS/014_请求参数间影响.html">
            
                <a href="../005_EBS/014_请求参数间影响.html">
            
                    
                    014_请求参数间影响
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.15" data-path="../005_EBS/015_FNDLOAD.html">
            
                <a href="../005_EBS/015_FNDLOAD.html">
            
                    
                    015_FNDLOAD
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.16" data-path="../005_EBS/016_配置文件.html">
            
                <a href="../005_EBS/016_配置文件.html">
            
                    
                    016_配置文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.17" data-path="../005_EBS/017_科目余额.html">
            
                <a href="../005_EBS/017_科目余额.html">
            
                    
                    017_科目余额
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.18" data-path="../005_EBS/018_供应商与客户.html">
            
                <a href="../005_EBS/018_供应商与客户.html">
            
                    
                    018_供应商与客户
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.19" data-path="../005_EBS/019_日记账.html">
            
                <a href="../005_EBS/019_日记账.html">
            
                    
                    019_日记账
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.20" data-path="../005_EBS/020_WebService发布与删除.html">
            
                <a href="../005_EBS/020_WebService发布与删除.html">
            
                    
                    020_WebService发布与删除
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.21" data-path="../005_EBS/021_报表开发.html">
            
                <a href="../005_EBS/021_报表开发.html">
            
                    
                    021_报表开发
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../006_FORM/001_数字格式设置.html">
            
                <a href="../006_FORM/001_数字格式设置.html">
            
                    
                    006_FORM
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../006_FORM/001_数字格式设置.html">
            
                <a href="../006_FORM/001_数字格式设置.html">
            
                    
                    001_数字格式设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../006_FORM/002_Form状态.html">
            
                <a href="../006_FORM/002_Form状态.html">
            
                    
                    002_Form状态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../006_FORM/003_窗口消息.html">
            
                <a href="../006_FORM/003_窗口消息.html">
            
                    
                    003_窗口消息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../006_FORM/004_Form环境配置.html">
            
                <a href="../006_FORM/004_Form环境配置.html">
            
                    
                    004_Form环境配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../006_FORM/005_打开窗口.html">
            
                <a href="../006_FORM/005_打开窗口.html">
            
                    
                    005_打开窗口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../006_FORM/006_日历LOV.html">
            
                <a href="../006_FORM/006_日历LOV.html">
            
                    
                    006_日历LOV
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../006_FORM/007_form系统变量.html">
            
                <a href="../006_FORM/007_form系统变量.html">
            
                    
                    007_form系统变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="../006_FORM/008_层级与安全.html">
            
                <a href="../006_FORM/008_层级与安全.html">
            
                    
                    008_层级与安全
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.9" data-path="../006_FORM/009_item间关联.html">
            
                <a href="../006_FORM/009_item间关联.html">
            
                    
                    009_item间关联
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.10" data-path="../006_FORM/010_FORM界面数字百分比显示.html">
            
                <a href="../006_FORM/010_FORM界面数字百分比显示.html">
            
                    
                    010_FORM界面数字百分比显示
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../007_工具/001_ASCLL对照表.html">
            
                <a href="../007_工具/001_ASCLL对照表.html">
            
                    
                    007_工具
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../007_工具/001_ASCLL对照表.html">
            
                <a href="../007_工具/001_ASCLL对照表.html">
            
                    
                    001_ASCLL对照表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../007_工具/002_HTML转义字符.html">
            
                <a href="../007_工具/002_HTML转义字符.html">
            
                    
                    002_HTML转义字符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../007_工具/003_HTTP CONTENT_TYPE.html">
            
                <a href="../007_工具/003_HTTP CONTENT_TYPE.html">
            
                    
                    003_HTTP CONTENT_TYPE
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../007_工具/004_HTTP状态码详解.html">
            
                <a href="../007_工具/004_HTTP状态码详解.html">
            
                    
                    004_HTTP状态码详解
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >012_时间日期处理</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x65E5;&#x671F;&#x4E0E;&#x65F6;&#x95F4;&#x7684;&#x76F8;&#x5173;&#x5904;&#x7406;">&#x65E5;&#x671F;&#x4E0E;&#x65F6;&#x95F4;&#x7684;&#x76F8;&#x5173;&#x5904;&#x7406;</h1>
<h2 id="sysdate&#x3001;systimestamp&#x3001;currentdate&#x3001;currenttimestamp">SYSDATE&#x3001;systimestamp&#x3001;current_date&#x3001;current_timestamp</h2>
<p>date&#x548C;timestamp&#x662F;&#x4E24;&#x79CD;&#x65F6;&#x95F4;&#x7C7B;&#x578B;&#xFF0C;&#x7CBE;&#x5EA6;&#x4E0D;&#x4E00;&#x6837;&#x3002;timestamp&#x7CBE;&#x786E;&#x5230;&#x6BEB;&#x79D2;&#xFF0C;date&#x7CBE;&#x786E;&#x5230;&#x79D2;&#x3002;timestamp&#x4F1A;&#x4FDD;&#x5B58;/&#x5C55;&#x793A;&#x51FA;&#x65F6;&#x533A;,date&#x4E0D;&#x4F1A;&#x3002;</p>
<p>sysdate&#x8FD4;&#x56DE;&#x7684;&#x662F;&#x7CFB;&#x7EDF;&#x7684;&#x65F6;&#x95F4;&#x3002;</p>
<p>systimestamp&#x4E5F;&#x662F;&#x5F53;&#x524D;&#x7CFB;&#x7EDF;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;</p>
<p>CURRENT_TIMESTAMP &#x4E0E;&#x65F6;&#x533A;&#x8BBE;&#x7F6E;&#x6709;&#x5173;&#xFF0C;&#x8FD4;&#x56DE;&#x7684;&#x79D2;&#x662F;&#x7CFB;&#x7EDF;&#x7684;&#xFF0C;&#x8FD4;&#x56DE;&#x7684;&#x65E5;&#x671F;&#x548C;&#x65F6;&#x95F4;&#x662F;&#x6839;&#x636E;&#x65F6;&#x533A;&#x8F6C;&#x6362;&#x8FC7;&#x7684;&#x3002;</p>
<p>current_date&#x662F;&#x5BF9;CURRENT_TIMESTAMP&#x51C6;&#x786E;&#x5230;&#x79D2;&#x7684;&#x56DB;&#x820D;&#x4E94;&#x5165;&#x3002;</p>
<pre><code class="lang-plsql">SELECT systimestamp      AS &quot;&#x7CFB;&#x7EDF;&#x5F53;&#x524D;&#x65F6;&#x95F4;&#x6233;&quot;,
       SYSDATE           AS &quot;&#x7CFB;&#x7EDF;&#x5F53;&#x524D;&#x65F6;&#x95F4;&quot;,
       dbtimezone        AS &quot;&#x6570;&#x636E;&#x5E93;&#x5F53;&#x524D;&#x65F6;&#x533A;&quot;,
       sessiontimezone   AS &quot;&#x4F1A;&#x8BDD;&#x5F53;&#x524D;&#x65F6;&#x533A;&quot;,
       current_date      AS &quot;&#x65F6;&#x533A;&#x5F53;&#x524D;&#x65F6;&#x95F4;&quot;,
       current_timestamp AS &quot;&#x65F6;&#x533A;&#x5F53;&#x524D;&#x65F6;&#x95F4;&#x6233;&quot;,
       localtimestamp    AS &quot;&#x4F1A;&#x8BDD;&#x65F6;&#x95F4;&#x6233;&quot;
  FROM dual;
</code></pre>
<p><img src="img/1570676442948.png" alt="1570676442948"></p>
<h2 id="tochar">to_char()</h2>
<pre><code class="lang-plsql">SELECT to_char(SYSDATE,
               &apos;yyyy-mm-dd hh24:mi;ss&apos;) AS &quot;&#x5177;&#x4F53;&#x65F6;&#x95F4;&quot;,
       to_char(SYSDATE,
               &apos;yyyy&apos;) AS &quot;&#x5E74;&quot;,
       to_char(SYSDATE,
               &apos;mm&apos;) AS &quot;&#x6708;&quot;,
       to_char(SYSDATE,
               &apos;dd&apos;) AS &quot;&#x65E5;&quot;,
       to_char(SYSDATE,
               &apos;day&apos;) AS &quot;&#x661F;&#x671F;(&#x4E2D;&#x6587;)&quot;,
       to_char(SYSDATE,
               &apos;day&apos;,
               &apos;NLS_DATE_LANGUAGE=American&apos;) AS &quot;&#x661F;&#x671F;&#xFF08;&#x82F1;&#x6587;&#xFF09;&quot;,
       to_char(SYSDATE,
               &apos;hh24&apos;) AS &quot;&#x65F6;&quot;,
       to_char(SYSDATE,
               &apos;mi&apos;) AS &quot;&#x5206;&quot;,
       to_char(SYSDATE,
               &apos;ss&apos;) AS &quot;&#x79D2;&quot;
  FROM dual;
</code></pre>
<p><img src="img/1570618059682.png" alt="1570618059682"></p>
<h2 id="todate">to_date()</h2>
<pre><code class="lang-plsql">SELECT to_date(&apos;2019-10-09 18:46;12&apos;,
               &apos;yyyy-mm-dd hh24:mi;ss&apos;)
  FROM dual;
</code></pre>
<h2 id="&#x6708;&#x5DEE;&#xFF1A;monthsbetween">&#x6708;&#x5DEE;&#xFF1A;months_between()</h2>
<pre><code class="lang-plsql">SELECT months_between(to_date(&apos;2019-10-01 &apos;,
                              &apos;yyyy-mm-dd hh24:mi;ss&apos;),
                      to_date(&apos;2019-7-31 &apos;,
                              &apos;yyyy-mm-dd &apos;)) AS &quot;&#x76F8;&#x5DEE;&#x6708;&#x6570;&quot;
  FROM dual;
</code></pre>
<p><img src="img/1570618611715.png" alt="1570618611715"></p>
<h2 id="&#x53D6;&#x4E0B;&#x4E00;&#x661F;&#x671F;&#x51E0;&#xFF1A;nextday">&#x53D6;&#x4E0B;&#x4E00;&#x661F;&#x671F;&#x51E0;&#xFF1A;next_day()</h2>
<pre><code class="lang-plsql">SELECT SYSDATE,
       next_day(SYSDATE,
                1) AS &quot;&#x4E0B;&#x4E00;&#x661F;&#x671F;&#x65E5;&quot;,
       next_day(SYSDATE,
                &apos;&#x661F;&#x671F;&#x4E00;&apos;) AS &quot;&#x4E0B;&#x4E00;&#x661F;&#x671F;&#x4E00;&quot;
  FROM dual;
</code></pre>
<p><img src="img/1570671044650.png" alt="1570671044650"></p>
<h2 id="&#x53D6;&#x5F53;&#x524D;&#x6708;&#x4EFD;&#x6700;&#x540E;&#x4E00;&#x5929;&#xFF1A;lastday">&#x53D6;&#x5F53;&#x524D;&#x6708;&#x4EFD;&#x6700;&#x540E;&#x4E00;&#x5929;&#xFF1A;last_day()</h2>
<pre><code class="lang-plsql">SELECT last_day(to_date(&apos;2019-7-2 &apos;,
                        &apos;yyyy-mm-dd &apos;)) AS &quot;&#x5F53;&#x6708;&#x6700;&#x540E;&#x65E5;&#x671F;&quot;
  FROM dual;
</code></pre>
<p><img src="img/1570703431357.png" alt="1570703431357"></p>
<h2 id="&#x53D6;&#x5F53;&#x524D;&#x6708;&#x4EFD;&#x7B2C;&#x4E00;&#x5929;">&#x53D6;&#x5F53;&#x524D;&#x6708;&#x4EFD;&#x7B2C;&#x4E00;&#x5929;</h2>
<h2 id="&#x8FD4;&#x56DE;&#x5F53;&#x5E74;&#x7B2C;&#x4E00;&#x5929;">&#x8FD4;&#x56DE;&#x5F53;&#x5E74;&#x7B2C;&#x4E00;&#x5929;</h2>
<h2 id="&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x5E74;&#x6708;&#x65E5;">&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x5E74;&#x6708;&#x65E5;</h2>
<h2 id="&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x661F;&#x671F;&#x7684;&#x7B2C;&#x4E00;&#x5929;">&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x661F;&#x671F;&#x7684;&#x7B2C;&#x4E00;&#x5929;</h2>
<h2 id="&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x65F6;&#x95F4;&#x5C0F;&#x65F6;&#x53D6;&#x6574;">&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x65F6;&#x95F4;&#x5C0F;&#x65F6;&#x53D6;&#x6574;</h2>
<h2 id="&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x65F6;&#x95F4;&#x5206;&#x949F;&#x53D6;&#x6574;">&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x65F6;&#x95F4;&#x5206;&#x949F;&#x53D6;&#x6574;</h2>
<pre><code class="lang-plsql">select trunc(sysdate) from dual  --&#x8FD4;&#x56DE;&#x5F53;&#x5929;
select trunc(sysdate, &apos;mm&apos;)   from   dual  --  &#x8FD4;&#x56DE;&#x5F53;&#x6708;&#x7B2C;&#x4E00;&#x5929;.
select trunc(sysdate,&apos;yy&apos;) from dual  --   &#x8FD4;&#x56DE;&#x5F53;&#x5E74;&#x7B2C;&#x4E00;&#x5929;
select trunc(sysdate,&apos;dd&apos;) from dual  --&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x5E74;&#x6708;&#x65E5;
select trunc(sysdate,&apos;yyyy&apos;) from dual  --  &#x8FD4;&#x56DE;&#x5F53;&#x5E74;&#x7B2C;&#x4E00;&#x5929;
select trunc(sysdate,&apos;d&apos;) from dual  --&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x661F;&#x671F;&#x7684;&#x7B2C;&#x4E00;&#x5929;
select trunc(sysdate, &apos;hh&apos;) from dual   --2019-7-18 14:00:00 &#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x65F6;&#x95F4;&#x5C0F;&#x65F6;&#x53D6;&#x6574; 
select trunc(sysdate, &apos;mi&apos;) from dual  --2019-7-18 14:43:00   &#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x65F6;&#x95F4;&#x5206;&#x949F;&#x53D6;&#x6574;
</code></pre>
<h2 id="&#x65F6;&#x95F4;&#x95F4;&#x9694;-interval">&#x65F6;&#x95F4;&#x95F4;&#x9694; INTERVAL</h2>
<p>&#x683C;&#x5F0F;&#xFF1A;</p>
<pre><code class="lang-plsql">--&#x683C;&#x5F0F;&#x4E00;&#xFF1A; &#x5E74;-&#x6708;
INTERVAL &apos;integer [- integer]&apos; {YEAR | MONTH} [(precision)][TO {YEAR | MONTH}]
--&#x683C;&#x5F0F;&#x4E8C;&#xFF1A; &#x5929; &#x65F6; &#x5206; &#x79D2;
INTERVAL &apos;{ integer | integer time_expr | time_expr }&apos;
{ { DAY | HOUR | MINUTE } [ (leading_precision) ]
| SECOND [ (leading_precision [, fractional_seconds_precision ]) ]
}
[ TO { DAY | HOUR | MINUTE | SECOND [ (fractional_seconds_precision) ] } ]
--&quot;integer&quot;&#x6307;&#x5B9A;&#x5929;&#x6570;&#x3002;&#x5982;&#x679C;&#x8FD9;&#x4E2A;&#x503C;&#x5305;&#x542B;&#x7684;&#x6570;&#x5B57;&#x8D85;&#x8FC7;&#x4E86;&#x4E3B;&#x8981;&#x7CBE;&#x5EA6;&#x6307;&#x5B9A;&#x7684;&#x6570;&#x5B57;&#xFF0C;&#x90A3;&#x4E48;Oracle&#x5C06;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x9519;&#x8BEF;&#x3002;
--&quot;time_expr&quot;&#x6307;&#x5B9A;&#x683C;&#x5F0F;HH:MI:SS&#x7684;&#x65F6;&#x95F4;&#x3002;
</code></pre>
<p>&#x8868;&#x793A;&#x4E00;&#x6BB5;&#x65F6;&#x95F4;&#x5DEE;, &#x6CE8;&#x610F;&#x65F6;&#x95F4;&#x5DEE;&#x53EA;&#x7CBE;&#x786E;&#x5230;&#x5E74;&#x548C;&#x6708;. precision&#x4E3A;&#x5E74;&#x6216;&#x6708;&#x7684;&#x7CBE;&#x786E;&#x57DF;, &#x6709;&#x6548;&#x8303;&#x56F4;&#x662F;0&#x5230;9, &#x9ED8;&#x8BA4;&#x503C;&#x4E3A;2
&#x5B9E;&#x9645;&#x6D4B;&#x4E86;&#x4E00;&#x4E0B;&#xFF0C;&#x597D;&#x50CF;&#x53EA;&#x6709;&#x5E74;&#x9700;&#x8981;&#x7CBE;&#x5EA6;&#xFF0C;&#x6708;&#x4E0D;&#x9700;&#x8981;&#xFF0C;&#x6709;&#x6CA1;&#x6709;&#x90FD;&#x4E0D;&#x5F71;&#x54CD;</p>
<p>&#x65E5;&#x671F;&#x7EC4;&#x5408;&#x53EA;&#x80FD;&#xFF08;&#x5E74;&#x6708;&#xFF09;&#x6216;&#xFF08;&#x5929;&#x65F6;&#x5206;&#x79D2;&#xFF09;</p>
<pre><code class="lang-plsql">--&#x62A5;&#x9519;&#xFF1A;&#x95F4;&#x9694;&#x7684;&#x524D;&#x5BFC;&#x7CBE;&#x5EA6;&#x592A;&#x5C0F;  &#x8F93;&#x5165;&#x5E74;&#x4E3A;111&#xFF0C;&#x7CBE;&#x5EA6;&#x4E3A;3&#xFF0C;&#x9ED8;&#x8BA4;&#x7CBE;&#x5EA6;&#x4E3A;2&#xFF0C;&#x5E94;&#x663E;&#x793A;&#x58F0;&#x660E;&#x7CBE;&#x5EA6;
SELECT SYSDATE AS &quot;&#x5F53;&#x524D;&#x65F6;&#x95F4;&quot;,
       SYSDATE + INTERVAL &apos;111-2&apos; YEAR TO MONTH AS &quot;111&#x5E74;2&#x6708;&#x540E;&quot;,
       SYSDATE - INTERVAL &apos;111-2&apos; YEAR TO MONTH AS &quot;111&#x5E74;2&#x6708;&#x524D;&quot;
  FROM dual;

--&#x62A5;&#x9519; &#x65E0;&#x6548;&#x7684;&#x6708;&#x4EFD; &#x5F53;&#x540C;&#x65F6;&#x5305;&#x542B;&#x5E74;&#x6708;&#x65F6;&#xFF0C;&#x6708;&#x4EFD;&#x53EA;&#x80FD;&#x8F93;&#x5165;0-11&#xFF0C;&#x4E14;&#x65E0;&#x6CD5;&#x9009;&#x62E9;&#x6708;&#x7CBE;&#x5EA6;
SELECT SYSDATE AS &quot;&#x5F53;&#x524D;&#x65F6;&#x95F4;&quot;,
       SYSDATE + INTERVAL &apos;111-22&apos; YEAR(3) TO MONTH AS &quot;111&#x5E74;2&#x6708;&#x540E;&quot;,
       SYSDATE - INTERVAL &apos;111-22&apos; YEAR(3) TO MONTH AS &quot;111&#x5E74;2&#x6708;&#x524D;&quot;
  FROM dual;

--&#x5E74;&#x6708;&#x7EC4;&#x5408;
SELECT SYSDATE AS &quot;&#x5F53;&#x524D;&#x65F6;&#x95F4;&quot;,
       SYSDATE + INTERVAL &apos;111-2&apos; YEAR(3) TO MONTH AS &quot;111&#x5E74;2&#x6708;&#x540E;&quot;,
       SYSDATE - INTERVAL &apos;111-2&apos; YEAR(3) TO MONTH AS &quot;111&#x5E74;2&#x6708;&#x524D;&quot;
  FROM dual;

--&#x6708;&#x4EFD;&#x6709;&#x65E0;&#x7CBE;&#x5EA6;&#x90FD;&#x4E00;&#x6837;
SELECT SYSDATE,
       SYSDATE + INTERVAL &apos;1000&apos; MONTH(2) AS &quot;1000&#x6708;&#x540E;&quot;,
       SYSDATE - INTERVAL &apos;1000&apos; MONTH AS &quot;1000&#x6708;&#x524D;&quot;
  FROM dual;

--&#x5F53;&#x540C;&#x65F6;&#x9700;&#x8981;&#x5E74;&#x6708;&#x4E14;&#x6708;&#x4EFD;&#x8D85;&#x8FC7;11&#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x591A;&#x6B21;&#x4F7F;&#x7528;INTERVAL
SELECT SYSDATE,
       SYSDATE + INTERVAL &apos;4&apos; YEAR + INTERVAL &apos;1000&apos; MONTH AS &quot;4&#x5E74;1000&#x6708;&#x540E;&quot;,
       SYSDATE - INTERVAL &apos;4&apos; YEAR - INTERVAL &apos;1000&apos; MONTH AS &quot;4&#x5E74;1000&#x6708;&#x524D;&quot;
  FROM dual;

--&#x5929;&#x65F6;&#x5206;&#x79D2;&#x7EC4;&#x5408;
SELECT SYSDATE,
       SYSDATE + INTERVAL &apos;1 01:01:01&apos; DAY TO SECOND
  FROM dual; --&#x5F53;&#x524D;&#x65F6;&#x95F4;+1&#x5929;1&#x5C0F;&#x65F6;1&#x5206;&#x949F;1&#x79D2;
</code></pre>
<h2 id="&#x589E;&#x51CF;&#x6708;&#x4EFD;&#xFF1A;addmonths">&#x589E;&#x51CF;&#x6708;&#x4EFD;&#xFF1A;add_months</h2>
<pre><code class="lang-plsql">SELECT SYSDATE AS &quot;&#x5F53;&#x524D;&#x65F6;&#x95F4;&quot;,
       add_months(SYSDATE,
                  7) AS &quot;&#x4E03;&#x6708;&#x4EFD;&quot;
  FROM dual;
</code></pre>
<h2 id="&#x622A;&#x53D6;&#x5E74;&#x6708;&#x65E5;&#x65F6;&#x5206;&#x79D2;extract">&#x622A;&#x53D6;&#x5E74;&#x6708;&#x65E5;&#x65F6;&#x5206;&#x79D2;extract()</h2>
<p>&#x53EA;&#x53EF;&#x4EE5;&#x4ECE;&#x4E00;&#x4E2A;date&#x7C7B;&#x578B;&#x4E2D;&#x622A;&#x53D6;&#x5E74;&#x6708;&#x65E5;&#xFF0C;&#x65E0;&#x6CD5;&#x622A;&#x53D6;&#x65F6;&#x5206;&#x79D2;</p>
<pre><code class="lang-plsql">SELECT extract(YEAR FROM SYSDATE) AS &quot;&#x5E74;&quot;,
       extract(MONTH FROM SYSDATE) AS &quot;&#x6708;&quot;,
       extract(DAY FROM SYSDATE) AS &quot;&#x65E5;&quot;
  FROM dual;
</code></pre>
<p><img src="img/1570702909384.png" alt="1570702909384"></p>
<p>&#x53EF;&#x4EE5;&#x4ECE;timestamp&#x4E2D;&#x83B7;&#x53D6;&#x5E74;&#x6708;&#x65E5;&#x65F6;&#x5206;&#x79D2;</p>
<pre><code class="lang-plsql">SELECT extract(YEAR FROM systimestamp) AS &quot;&#x5E74;&quot;,
       extract(MONTH FROM systimestamp) AS &quot;&#x6708;&quot;,
       extract(DAY FROM systimestamp) AS &quot;&#x65E5;&quot;,
       extract(hour FROM systimestamp) AS &quot;&#x65F6;&quot;,
       extract(minute FROM systimestamp) AS &quot;&#x5206;&quot;,
       extract(SECOND FROM systimestamp) AS &quot;&#x79D2;&quot;
  FROM dual;
</code></pre>
<p><img src="img/1570702959248.png" alt="1570702959248"></p>
<p>&#x83B7;&#x53D6;&#x4E24;&#x4E2A;&#x65E5;&#x671F;&#x4E4B;&#x95F4;&#x7684;&#x5177;&#x4F53;&#x65F6;&#x95F4;&#x95F4;&#x9694;</p>
<pre><code class="lang-plsql">SELECT extract(DAY FROM dt2 - dt1) AS &quot;&#x76F8;&#x5DEE;&#x5929;&#x6570;&quot;,
       extract(hour FROM dt2 - dt1) AS &quot;&#x76F8;&#x5DEE;&#x5C0F;&#x65F6;&quot;,
       extract(minute FROM dt2 - dt1) AS &quot;&#x76F8;&#x5DEE;&#x5206;&quot;,
       extract(SECOND FROM dt2 - dt1) AS &quot;&#x76F8;&#x5DEE;&#x79D2;&quot;
  FROM (SELECT to_timestamp(&apos;2017-9-04 15:07:00&apos;,
                            &apos;yyyy-mm-dd hh24:mi:ss&apos;) dt1,
               to_timestamp(&apos;2019-10-17 19:08:46&apos;,
                            &apos;yyyy-mm-dd hh24:mi:ss&apos;) dt2
          FROM dual);
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="011_序列流水号.html" class="navigation navigation-prev " aria-label="Previous page: 011_序列流水号">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="013_死锁.html" class="navigation navigation-next " aria-label="Next page: 013_死锁">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"012_时间日期处理","level":"1.5.12","depth":2,"next":{"title":"013_死锁","level":"1.5.13","depth":2,"path":"004_Oracle/013_死锁.md","ref":"004_Oracle/013_死锁.md","articles":[]},"previous":{"title":"011_序列流水号","level":"1.5.11","depth":2,"path":"004_Oracle/011_序列流水号.md","ref":"004_Oracle/011_序列流水号.md","articles":[]},"dir":"ltr"},"config":{"plugins":["github","splitter","-lunr","-search","search-plus","simple-page-toc","copy-code-button","page-toc-button","back-to-top-button","chapter-fold","auto-scroll-table","-sharing","livereload"],"root":".","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"chapter-fold":{},"github":{"url":"https://github.com/xiajiajinxuan"},"livereload":{},"simple-page-toc":{"maxDepth":3,"skipFirstH1":false},"splitter":{},"auto-scroll-table":{},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"page-toc-button":{"maxTocDepth":2,"minTocSize":2},"back-to-top-button":{},"copy-code-button":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"search-plus":{}},"theme":"default","author":"xiajiajinxuan","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"瑕家瑾轩_Note","language":"zh-hans","gitbook":"*","description":"瑕家瑾轩_Note"},"file":{"path":"004_Oracle/012_时间日期处理.md","mtime":"2020-04-21T10:09:39.583Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-08-17T07:13:06.707Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-auto-scroll-table/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

